/*
 * Created by JFormDesigner on Fri May 31 22:18:45 EDT 2013
 */

import CreateNewItem.CreateNewItem;
import MaintMenu.MaintMenu;
import MaintMenu.VenPricingUpdTBLN.FindItemByVendorSheetPL;
import PartsLookUp.PartsLookupByPL;
import PartsLookUp.dnkNumToPL;
import plUpdate.PLUpdate;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author Jason Chi
 */
public class MainMenu extends JFrame {
    long s1 = System.currentTimeMillis();

    //custom added variables


    public MainMenu() {
        initComponents();
        //below to bypass menu and start createitem
//        CreateNewItem newItem = new CreateNewItem();
//        newItem.setVisible(true);




    }

    private void button1ActionPerformed(ActionEvent e) {
//        if (s1 <=1401935009751l){
            PLUpdate applet = new PLUpdate();
            JFrame frame = new JFrame();
            frame.setSize(500, 175);
    //        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setTitle("Update Parts Link Number");
            frame.getContentPane().add(applet, BorderLayout.CENTER);
            applet.init();
            applet.start();
            frame.setLocationRelativeTo(null); // Center the frame
            frame.setVisible(true);
            frame.repaint();
            applet.repaint();
            frame.setIconImage(new ImageIcon(getClass().getResource("/images/greenarrow.jpg")).getImage());

//
//        }else{
//            System.out.println("Software review required to ensure proper software operation");
//
//        }






    }

    //To access Maintnance menu, Scroll Lock need to be on, then (*)
    private void plUpdateKeyTyped(KeyEvent e) {

        char c = e.getKeyChar();
        boolean isCapOn = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_SCROLL_LOCK);

        if(c=='*'){
            //System.out.println("*");
            if(isCapOn){
                //System.out.println(isCapOn);

//            this.setState(Frame.ICONIFIED);
            MaintMenu maint = new MaintMenu();
            maint.setIconImage(new ImageIcon(getClass().getResource("/images/greenarrow.jpg")).getImage());
            maint.setVisible(true);
                //maint.setAlwaysOnTop(false);
//            this.setVisible(true);


            }
        }else{}
    }

    private void itemLookupbyPLActionPerformed(ActionEvent e) {


        this.setVisible(false);
//        PartsLookupByPL appletpl = new PartsLookupByPL();
        CreateNewItem createNewItem = new CreateNewItem();
        createNewItem.setVisible(true);
        createNewItem.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        createNewItem.
//        this.setVisible(true);


    }
    public void minFrame(){
        this.setState(Frame.ICONIFIED);
    }

    public void resFrame(){
        this.setState(Frame.NORMAL);
    }

    private void findButActionPerformed(ActionEvent e) {
//        String a="TW";
//        String b="AU3010128";
//        int c=5;

//        System.out.println(a + b + c);

//        System.out.println("Searching TW Vendor Cost");
        FindItemByVendorSheetPL findItemByVendorSheetPL0 = new FindItemByVendorSheetPL("TW",partFind.getText(),6);
//        System.out.println("Searching TX Vendor Cost");
        FindItemByVendorSheetPL findItemByVendorSheetPL1 = new FindItemByVendorSheetPL("TX",partFind.getText(),3);
//        System.out.println("Searching GN Vendor Cost");
        FindItemByVendorSheetPL findItemByVendorSheetPL2 = new FindItemByVendorSheetPL("GN",partFind.getText(),1);
//        System.out.println("Searching DP Vendor Cost");
        FindItemByVendorSheetPL findItemByVendorSheetPL3 = new FindItemByVendorSheetPL("DP",partFind.getText(),4);
//        System.out.println("Searching YCC Vendor Cost");
        FindItemByVendorSheetPL findItemByVendorSheetPL4 = new FindItemByVendorSheetPL("YCC",partFind.getText(),1);
//        System.out.println("Searching AP Vendor Cost");
        FindItemByVendorSheetPL findItemByVendorSheetPL5 = new FindItemByVendorSheetPL("AP",partFind.getText(),1);
//        System.out.println("Search Completed");
        System.out.println("");
        JOptionPane.showMessageDialog(null, " Search Completed.");

    }

    private void dnkToplActionPerformed(ActionEvent e) {
        dnkNumToPL dnkNumToPL = new dnkNumToPL(dnkFind.getText());
//        foundPL.setText(dnkNumToPL.getNum());
//        partFind.setText(dnkNumToPL.getNum());
        //        System.out.println("Searching TW Vendor Cost");
        FindItemByVendorSheetPL findItemByVendorSheetPL0 = new FindItemByVendorSheetPL("TW",dnkNumToPL.getNum(),6);
//        System.out.println("Searching TX Vendor Cost");
        FindItemByVendorSheetPL findItemByVendorSheetPL1 = new FindItemByVendorSheetPL("TX",dnkNumToPL.getNum(),3);
//        System.out.println("Searching GN Vendor Cost");
        FindItemByVendorSheetPL findItemByVendorSheetPL2 = new FindItemByVendorSheetPL("GN",dnkNumToPL.getNum(),1);
//        System.out.println("Searching DP Vendor Cost");
        FindItemByVendorSheetPL findItemByVendorSheetPL3 = new FindItemByVendorSheetPL("DP",dnkNumToPL.getNum(),4);
//        System.out.println("Searching YCC Vendor Cost");
        FindItemByVendorSheetPL findItemByVendorSheetPL4 = new FindItemByVendorSheetPL("YCC",dnkNumToPL.getNum(),1);
//        System.out.println("Searching AP Vendor Cost");
        FindItemByVendorSheetPL findItemByVendorSheetPL5 = new FindItemByVendorSheetPL("AP",dnkNumToPL.getNum(),1);
//        System.out.println("Search Completed");
        dnkNumToPL=null;
//        System.out.println("");

        JOptionPane.showMessageDialog(null, " Search Completed.");
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        // Generated using JFormDesigner Evaluation license - jason Chi
        label1 = new JLabel();
        plUpdate = new JButton();
        CreateNewItem = new JButton();
        partFind = new JTextField();
        findBut = new JButton();
        dnkFind = new JTextField();
        dnkTopl = new JButton();

        //======== this ========
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new Dimension(24, 60));
        setName("Main Menu");
        setTitle("MileStone Bodyparts");
        setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
        setIconImage(new ImageIcon(getClass().getResource("/images/greenarrow.jpg")).getImage());
        Container contentPane = getContentPane();
        contentPane.setLayout(new GridBagLayout());
        ((GridBagLayout)contentPane.getLayout()).columnWidths = new int[] {24, 151, 204, 139, 54, 81, 0};
        ((GridBagLayout)contentPane.getLayout()).rowHeights = new int[] {14, 0, 28, 0, 0, 0, 0, 0, 0, 0, 0};
        ((GridBagLayout)contentPane.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
        ((GridBagLayout)contentPane.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

        //---- label1 ----
        label1.setText("Main Menu");
        label1.setFont(new Font("Dialog", Font.BOLD, 18));
        contentPane.add(label1, new GridBagConstraints(2, 1, 3, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.VERTICAL,
            new Insets(0, 0, 5, 5), 0, 0));

        //---- plUpdate ----
        plUpdate.setText("PartsLink Update");
        plUpdate.setFocusCycleRoot(true);
        plUpdate.setInheritsPopupMenu(true);
        plUpdate.setHorizontalTextPosition(SwingConstants.CENTER);
        plUpdate.setSelected(true);
        plUpdate.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                button1ActionPerformed(e);
            }
        });
        plUpdate.addKeyListener(new KeyAdapter() {
            @Override
            public void keyTyped(KeyEvent e) {
                plUpdateKeyTyped(e);
            }
        });
        contentPane.add(plUpdate, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 5), 0, 0));

        //---- CreateNewItem ----
        CreateNewItem.setText("Create New Items");
        CreateNewItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                itemLookupbyPLActionPerformed(e);
            }
        });
        contentPane.add(CreateNewItem, new GridBagConstraints(3, 3, 2, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 5), 0, 0));

        //---- partFind ----
        partFind.setText("PLnum");
        contentPane.add(partFind, new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 5), 0, 0));

        //---- findBut ----
        findBut.setText("Cost Check From Vendor's Price List (PL#)");
        findBut.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                findButActionPerformed(e);
            }
        });
        contentPane.add(findBut, new GridBagConstraints(3, 6, 2, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 5), 0, 0));

        //---- dnkFind ----
        dnkFind.setText("DNKnum");
        contentPane.add(dnkFind, new GridBagConstraints(2, 8, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 5), 0, 0));

        //---- dnkTopl ----
        dnkTopl.setText("Cost Check From Vendor's Price List (DNK#)");
        dnkTopl.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dnkToplActionPerformed(e);
            }
        });
        contentPane.add(dnkTopl, new GridBagConstraints(3, 8, 2, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 5), 0, 0));
        setSize(640, 350);
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    // Generated using JFormDesigner Evaluation license - jason Chi
    private JLabel label1;
    private JButton plUpdate;
    private JButton CreateNewItem;
    private JTextField partFind;
    private JButton findBut;
    private JTextField dnkFind;
    private JButton dnkTopl;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
